function [Ypred] = rrsvm(data,label,k)
%RRSVM function [Ypred] = rrsvm(data,label,k)
%       reduced rank svm
%       uses a linear kernel and decompose in its eigenspace
%       solves a reduced quadratic programing problem
% 
%       version 0.1, 04/08/2014
%       Suqi Liu

X = double(data);
Y = double(label);
n = size(data,1);
l = size(label,1);

K = X*X';
clear X;
K = K/max(max(K));
[V,D] = eigs(K,k);

%M = inv(D);
M = rand(k);
M = M'*M;
P = repmat(Y,1,k).*V(1:l,:);
clear Y;
Q = V(l+1:n,:);
clear V;
clear D;

cvx_begin
cvx_solver sedumi
    variable gam(k,1)
    minimize (gam'*M*gam)
    subject to
        P*gam >= ones(l,1)
cvx_end

Ypred = int8(sign(Q*gam));
end